package com.sinodata.bsm.cicp.collector.was7;

//was7的采集程序现在没有用到，这里面用到了websphere的架包，没有加架包会报错，所以全部注释掉
//package com.union.collector.was7;
//
//import java.util.ArrayList;
//import java.util.List;
//import java.util.Set;
//
//import javax.management.MBeanServerConnection;
//import javax.management.ObjectName;
//import javax.management.remote.JMXConnector;
//
//import org.apache.log4j.Logger;
//
//import com.ibm.websphere.pmi.stat.WSStatistic;
//import com.ibm.websphere.pmi.stat.WSStats;
//import com.ibm.ws.pmi.stat.AverageStatisticImpl;
//import com.ibm.ws.pmi.stat.BoundedRangeStatisticImpl;
//import com.ibm.ws.pmi.stat.CountStatisticImpl;
//import com.ibm.ws.pmi.stat.RangeStatisticImpl;
//import com.union.pub.collector.Collector;
//import com.union.pub.exception.CollectorException;
//import com.union.pub.util.JmxUtil;
//import com.union.pub.vo.vox.ResPropertyValueX;
//
//public class JdbcPoolWas7Collector extends Collector {
//
//    private static final Logger logger = Logger.getLogger(JdbcPoolWas7Collector.class);
//
//    @Override
//    public List<ResPropertyValueX> collect(String ip) throws CollectorException {
//        List<ResPropertyValueX> value = new ArrayList<ResPropertyValueX>();
//        ResPropertyValueX propertyValueX = new ResPropertyValueX();
//        String[] propMetas = getPropMeta();
//        WSStats stats;
//        ResPropertyValueX.PropValue[] proValues = new ResPropertyValueX.PropValue[getPropMeta().length];
//        String serverName = this.getParamMap().get("serverName");
//        String jdbcPoolName = this.getParamMap().get("jdbcPoolName");
//        String nodeName = this.getParamMap().get("nodeName");
//        JMXConnector connector = null;
//        ObjectName prefMbean = null;
//        ObjectName nodeAgent = null;
//
//        try {
//            ObjectName querybean = new ObjectName("WebSphere:type=Perf,*");
//            String query = "WebSphere:type=JDBCProvider,name=" + jdbcPoolName + ",process=" + serverName + ",node=" + nodeName + ",*";
//            ObjectName queryName = new ObjectName(query);
//            connector = JmxUtil.getConnection(JmxUtil.WEBSPHERE7, ip + ":" + this.getParamMap().get("serverPort"));
//            MBeanServerConnection mbsc = connector.getMBeanServerConnection();
//            Set pref = mbsc.queryNames(querybean, null);
//            if (!pref.isEmpty()) {
//                prefMbean = (ObjectName) pref.iterator().next();
//            }
//            Set s = mbsc.queryNames(queryName, null);
//            if (!s.isEmpty()) {
//                nodeAgent = (ObjectName) s.iterator().next();
//            }
//            String[] signature = new String[] { "javax.management.ObjectName", "java.lang.Boolean" };
//            Object[] params = new Object[] { nodeAgent, new Boolean(false) };
//            stats = (WSStats) mbsc.invoke(prefMbean, "getStatsObject", params, signature);
//            WSStatistic[] data = stats.getStatistics();
//            for (int i = 0; i < data.length; i++) {
//                if (data[i] instanceof CountStatisticImpl) {
//                    CountStatisticImpl e = (CountStatisticImpl) data[i];
//                    if ("CreateCount".equals(e.getName())) {
//                        proValues[0] = ResPropertyValueX.createPropValue(e.getCount() + "", propMetas[0]);
//                    }else if("CloseCount".equals(e.getName())){
//                        proValues[1] = ResPropertyValueX.createPropValue(e.getCount() + "", propMetas[1]);
//                    }
//                }else if(data[i] instanceof BoundedRangeStatisticImpl){
//                    BoundedRangeStatisticImpl e1 = (BoundedRangeStatisticImpl)data[i];
//                    if("PoolSize".equals(e1.getName())){
//                        proValues[2] = ResPropertyValueX.createPropValue(e1.getUpperBound() + "", propMetas[2]);
//                    }else if("FreePoolSize".equals(e1.getName())){
//                        proValues[3] = ResPropertyValueX.createPropValue(e1.getCurrent() + "", propMetas[3]);
//                    }
//                }else if(data[i] instanceof RangeStatisticImpl){
//                    RangeStatisticImpl e2 = (RangeStatisticImpl)data[i];
//                    if("WaitingThreadCount".equals(e2.getName())){
//                        proValues[4] = ResPropertyValueX.createPropValue(e2.getCurrent() + "", propMetas[4]);
//                    }else if("PercentUsed".equals(e2.getName())){
//                        proValues[5] = ResPropertyValueX.createPropValue(e2.getCurrent() + "", propMetas[5]);
//                    }
//                }else if(data[i] instanceof AverageStatisticImpl){
//                    AverageStatisticImpl e3 = (AverageStatisticImpl)data[i];
//                    if("UseTime".equals(e3.getName())){
//                        proValues[6] = ResPropertyValueX.createPropValue(e3.getTotal() + "", propMetas[6]);
//                    }else if("WaitTime".equals(e3.getName())){
//                        proValues[7] = ResPropertyValueX.createPropValue(e3.getTotal() + "", propMetas[7]);
//                    }
//                }
//                propertyValueX.setValues(proValues);
//                value.add(propertyValueX);
//            }
//        } catch (Exception e) {
//            logger.error("failed to collect by JVMCollector", e);
//        } finally {
//            JmxUtil.closeConnector(connector);
//        }
//        return value;
//    }
//
//    @Override
//    public String[] getParamMeta() {
//        //        return new String[] { "服务器端口","jdbc连接池名","服务器名", "节点名" };
//        return new String[] { "serverPort", "jdbcPoolName", "serverName", "nodeName" };
//    }
//
//    @Override
//    public String[] getPropMeta() {
//        //        return new String[] { "创建数", "关闭数", "jdbc池大小", "空闲大小", "等待线程数", "使用率", "使用时间", "空闲时间" };
//        return new String[] { "CreationNum", "CloseNum", "JDBCPoolSize", "FreeSize", "WaitThreadsNum", "Usage", "UseTime", "FreeTime" };
//    }
//
//}
